﻿using System;
using Csla.Xaml;
using Accounting.Library;
using System.ComponentModel;
using Utility;
using Accounting.Library.Utility;



namespace csla4Skeleton.UI.SL.NghiepVu.TaiSanCoDinh.DM_DoiTuongTHCP
{
    public class DM_DoiTuongTHCP_ViewModel : ViewModel<Accounting.Library.DM_DoiTuongTHCP>
    {
        #region Event Declare
        public delegate void ChildList_AddedNew_EventHandler(object sender, ChildListAddedNewArgs e);
       
        public delegate void HangHoaIdChanged_EventHandler(object sender, HangHoaIdChangedEventArgs e);

        public event ChildList_AddedNew_EventHandler ChildList_AddedNew;

        public event EventHandler TCHangHoaChanged;
       
        public event EventHandler Saved;
        public event EventHandler Canceled;
        public event HangHoaIdChanged_EventHandler hangHoaIdChanged;
       
        
        #endregion

        #region Refresh Model

        public DM_DoiTuongTHCP_ViewModel(string mode)
        {
            if (mode.Equals(BusinessConfiguration.Configuration.ChildWindow))
            {
                this.BeginRefresh("NewDM_DoiTuongTHCP");
            }
           
        }
        public DM_DoiTuongTHCP_ViewModel()
        {
            BeginRefresh("NewDM_DoiTuongTHCP");
            
        }

        public DM_DoiTuongTHCP_ViewModel(int Khoa)
        {
            BeginRefresh("GetDM_DoiTuongTHCP", Khoa);
           
        }

        public void NewDM_DoiTuongTHCPViewModel()
        {
            BeginRefresh("NewDM_DoiTuongTHCP");
            
        }

        public void GetDM_DoiTuongTHCPViewModel(int Khoa)
        {
            BeginRefresh("GetDM_DoiTuongTHCP", Khoa);
        }

        protected override void OnSaved()
        {
            base.OnSaved();
            if (Saved != null)
            {
                Saved(this, EventArgs.Empty);
            }
        }

        protected override void DoCancel()
        {
            base.DoCancel();
            if (Canceled != null)
            {
                Canceled(this, EventArgs.Empty);
            }
        }
        public void SaveAndNew()
        {
            BeginSave();
            NewDM_DoiTuongTHCPViewModel();
        }
        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                Model.DM_DoiTuongTHCP_ThanhPhams.AddedNew += new EventHandler<Csla.Core.AddedNewEventArgs<DM_DoiTuongTHCP_ThanhPhamChild>>(DM_DoiTuongTHCP_ThanhPhams_AddedNew);
                Model.TinhChatHangHoaChanged += new EventHandler(OnTinhChatHangHoaChanged);
                Model.HangHoaIdChanged += new EventHandler<HangHoaIdChangedEventArgs>(OnHangHoaIdChanged);
                
            }
        }
        #endregion
        
        #region Add DM_DoiTuongTHCP Details Item
        public void AddDM_DoiTuongTHCP_ThanhPhamItem()
        {
            Model.DM_DoiTuongTHCP_ThanhPhams.AddNewItem(Model.Khoa);
        }



        void DM_DoiTuongTHCP_ThanhPhams_AddedNew(object sender, Csla.Core.AddedNewEventArgs<DM_DoiTuongTHCP_ThanhPhamChild> e)
        {
            OnChildList_AddedNew(sender, new ChildListAddedNewArgs("DM_DoiTuongTHCP_ThanhPhams"));
        }      

        protected virtual void OnChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (ChildList_AddedNew != null)
            {
                //Invokes the delegates.
                ChildList_AddedNew(sender, e);
            }
        }

      
        public void OnHangHoaIdChanged(object sender, HangHoaIdChangedEventArgs e)
        {

            hangHoaIdChanged(sender, e);

        }
        public void OnTinhChatHangHoaChanged(object sender, EventArgs e)
        {

            TCHangHoaChanged(sender, e);

        }

        #endregion

        #region Delete DM_DoiTuongTHCP Details Item

        public void DeleteDM_DoiTuongTHCP_ThanhPhamItem(int Index)
        {
            Model.DM_DoiTuongTHCP_ThanhPhams.DeleteItem(Index);
        }


        #endregion
    }
}
